//引入Token处理的controller
const Token = require('../../controllers/token');
const Constant = require('../../constant/constant'); //引入常量
//配置对象
const exportObj = {
    verifyToken
};

function verifyToken (req,res,next){//验证Token中间件
    //如果请求路径是/login登录页，则跳过此步进行下一步
    if(req.path === '/login') return next();
    let token = req.headers.token;
    //调用TokenController中的Token解密方法，对参数token进行解密
    let tokenVerifyObj = Token.decrypt(token);
    console.log(tokenVerifyObj.token)
    if(tokenVerifyObj.token){
        next();
    }else{
        res.json(Constant.TOKEN_ERROR);
    }
};

module.exports = exportObj;//导出对象